//
//  TitleViewController.m
//  忘不了
//
//  Created by rimi on 16/7/16.
//  Copyright © 2016年 handuan. All rights reserved.
//

#import "TitleViewController.h"
#import "SDAutoLayout.h"

@interface TitleViewController ()<UITextFieldDelegate>
@property (nonatomic,strong) UIView *titleView;
@property (nonatomic,strong) UITextField *titleTextField;
@property (nonatomic,strong) UIImageView *bgImageView;
@end

@implementation TitleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self loadUI];
    
}

- (void)loadUI{
    
    _bgImageView = [[UIImageView alloc]init];
    [_bgImageView setImage:[UIImage imageNamed:@"s"]];
    [self.view addSubview:_bgImageView];
    _bgImageView.sd_layout.topSpaceToView(self.view,0).leftSpaceToView(self.view,0).rightSpaceToView(self.view,0).bottomSpaceToView(self.view,0);
    
    _titleView = [[UIView alloc]init];
    [self.view addSubview:_titleView];
    _titleView.sd_layout.leftSpaceToView(self.view,0).rightSpaceToView(self.view,0).topSpaceToView(self.view,100).heightIs(60);
    
    _titleTextField = [[UITextField alloc]init];
    
    _titleTextField.text = _titleString;
    
    
    
    _titleTextField.borderStyle = UITextBorderStyleNone;
    _titleTextField.keyboardType = UIKeyboardTypeDefault;
    _titleTextField.clearButtonMode = UITextFieldViewModeAlways;
    //直接进入到编辑状态
    [_titleTextField becomeFirstResponder];
    _titleTextField.delegate = self;
    [self.titleView addSubview:_titleTextField];
    _titleTextField.sd_layout.leftSpaceToView(self.titleView,10).rightSpaceToView(self.titleView,10).topSpaceToView(self.titleView,0).bottomSpaceToView(self.titleView,0);
}

#pragma mark -- UITextFieldDelegate
//return点击事件
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if ([string isEqualToString:@"\n"]) {
        //调用协议方法
        if (_delegate && [_delegate respondsToSelector:@selector(addTitle:)]) {
            [_delegate addTitle:_titleTextField.text];
        }
        [self.navigationController popViewControllerAnimated:YES];
        return NO;
    }
    return YES;
}


@end
